package com.deplume.ssm.service.impl.admin.home;

import com.deplume.ssm.mapper.home.IRegisterMapper;
import com.deplume.ssm.pojo.home.Register;
import com.deplume.ssm.service.inface.admin.home.IRegisterService;
import com.deplume.ssm.util.MathUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by libing on 2016/8/4.
 */
@Service("registerService")
public class RegisterServiceImpl implements IRegisterService {

    @Autowired
    IRegisterMapper registerMapper;

    @Override
    public int isExistCustomer(String email) throws Exception {
        return registerMapper.isExistCustomer(email);
    }

    @Override
    public int insertCustomer(Register register) throws Exception {
        //加密规则，将生成的9位随机数放在原密码前面
        register.setSalt(MathUtil.getRandomString(9));
        System.out.println("============================");
        System.out.println(register.getSalt());
        System.out.println(register.getPassword());
        register.setPassword(register.getSalt()+register.getPassword());
        System.out.println(register.getPassword());
        System.out.println("=============================");
        return registerMapper.insertCustomer(register);
    }

    @Override
    public int isExistCompany(String email) throws Exception {
        return registerMapper.isExistCompany(email);
    }

    @Override
    public int insertCompany(Register register) throws Exception {
        register.setSalt(MathUtil.getRandomString(9));
        System.out.println("============================");
        System.out.println(register.getSalt());
        System.out.println(register.getPassword());
        register.setPassword(register.getSalt()+register.getPassword());
        System.out.println(register.getPassword());
        System.out.println("=============================");
        return registerMapper.insertCompany(register);
    }

    @Override
    public String getUserPW(String email) throws Exception {
        return registerMapper.getUserPW(email);
    }

    @Override
    public String getCompanyPW(String email) throws Exception {
        return registerMapper.getCompanyPW(email);
    }
}
